package card;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class CardGame {

    private static final String[] suits = {"♣","♥","♠","♦"};

    public List<Card> buyCard() {

        List<Card> cardlist = new ArrayList<>();

        for(int i = 0; i < 4; i++) {//四种花色
            for(int j = 1; j <= 13; j++) {//每种花色都有13张牌
                String suit = suits[i];
                int rank = j;

                Card card = new Card(suit, rank);
                cardlist.add(card);//每次把牌都放在list容器里

            }
        }

        return cardlist;
    }


    //洗牌
    public void shuffle(List<Card> cardList) {
        Random random = new Random();
        for(int i = cardList.size() - 1; i > 0; i--) {
            int indext = random.nextInt(i);
            swap(cardList, i, indext);//数组传过去，这张牌传过去，这张牌所在的下标传过去
        }
    }


    public void swap(List<Card> cardList, int i, int j) {
        Card tmp = cardList.get(i);
        cardList.set(i, cardList.get(j));
        cardList.set(j, tmp);
    }



}
